package com.ssyt.ssh.sys.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.ssyt.ssh.sys.entity.Article;
import com.ssyt.ssh.sys.entity.Blog;
import com.ssyt.ssh.sys.entity.Category;
import com.ssyt.ssh.sys.entity.Discuss;
import com.ssyt.ssh.sys.service.ArticleService;
import com.ssyt.ssh.sys.service.BlogService;
import com.ssyt.ssh.sys.service.CategoryService;
import com.ssyt.ssh.sys.service.DiscussService;

@Controller
@RequestMapping("/sys")
public class ArticleController {

	@Autowired
	private ArticleService article;

	@Autowired
	private CategoryService category;

	@Autowired
	private BlogService blog;

	@Autowired
	private DiscussService discuss;

	@ResponseBody
	@RequestMapping("/listTitle")
	public List<Article> listTitle() {
		return article.listTitle();
	}

	@RequestMapping("/listOne")
	public String listOne(@RequestParam String id, Model model) {
		int userId = Integer.parseInt(id);
		model.addAttribute("list", article.listOne(userId));
		model.addAttribute("cate", category.listCate(userId));
		model.addAttribute("discuss",discuss.listOneDisscuss());
		return "views/sys/particulars";
	}

	@ResponseBody
	@RequestMapping("/listArticle")
	public List<Article> listArticle() {
		return article.listArticle();
	}

	@ResponseBody
	@RequestMapping("/listAllCate")
	public List<Category> listAllCate() {
		return category.listAllCate();
	}

	@ResponseBody
	@RequestMapping("/listBlog")
	public List<Blog> listBlog() {
		return blog.listBlog();
	}

	@ResponseBody
	@RequestMapping("/listDiscuss")
	public List<Discuss> listDiscuss() {
		return discuss.listDiscuss();
	}
}
